package com.team01.pokemon.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.team01.pokemon.entity.Types;
import com.team01.pokemon.result.Result;
import com.team01.pokemon.service.TypesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 宝可梦属性表 前端控制器
 * </p>
 *
 * @author author
 * @since 2025-09-13
 */
@RestController
@RequestMapping("/types")
public class TypesController {

    @Autowired
    private TypesService typesService;

    /**
     * 查询属性类型列表
     * 
     * @param query 可选的搜索关键词
     * @return 属性类型列表
     */
    @GetMapping
    public Result list(String query) {
        // 封装查询条件
        LambdaQueryWrapper<Types> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(StringUtils.hasLength(query), Types::getTypeName, query);

        // 执行查询
        List<Types> list = typesService.list(wrapper);
        if (!CollectionUtils.isEmpty(list)) {
            return new Result(true, "查询属性类型列表成功", list);
        }
        return new Result(false, "查询属性类型列表失败", null);
    }
}
